<template>
  <div class="cluepayContainer">
    <payQRCode ref="payQRCode" @callback="closePay" @cancel="cancel"></payQRCode>
  </div>
</template>

<script>
import payQRCode from "../../common/payQRCode";
var vm;
export default {
  data: function() {
    return {
      clue: null,
      countList: [],
      info: {}
    };
  },
  components: {
    payQRCode
  },
  methods: {
    init: function(clue, countList, info) {
      vm.clue = clue;
      vm.countList = countList;
      vm.info = info;
      let goods_name = "";
	  let goods_money = "";
	  let payTitle = "";
      //从选择的班级、课程、商品中获取信息
      countList.forEach(item => {
        if (item.type == "班级") {
			payTitle += payTitle == '' ? item.className : '、' + item.className;
          goods_name +=
            goods_name == "" ? item.className : "," + item.className;
          goods_money +=
            goods_money == "" ? item.courseMoney : "," + item.courseMoney;
        } else if (item.type == "课程") {
		payTitle += payTitle == '' ? item.name : '、' + item.name;
          goods_name +=
            goods_name == "" ? item.name : "," + item.name;
          goods_money +=
            goods_money == "" ? item.realMoney : "," + item.realMoney;
        }
      });

      let detail = {
        goods_name: goods_name,
        goods_num: goods_money,
        body: window.config.projectName + "- 支付"
      };
      //支付参数
      let paras = {
        outTradeNo: info.orderSigupId, //商户订单号
        totalFee: info.realMoney * 100,
        // totalFee: 1, //金额,暂时设为1分钱，便于测试
        body: window.config.projectName + "- 支付", //显示在支付界面的标题
        tradeType: "NATIVE",
        detail: JSON.stringify(detail),
        campusId: this.$store.state.campusId
	  };
	  let payInfo ={
		  orderParas:paras,
		  payTitle:payTitle,
		  payName:info.payName
	  }
	  vm.$refs.payQRCode.init(payInfo);
	},
	closePay(){
		vm.$emit('ok', vm.countList, vm.info);
	},
    cancel: function() {
      vm.$emit("back");
    }
  },
  created: function() {
    vm = this;
  }
};
</script>
